package LeetcodeTest_seventeen;
//最长公共前缀
public class longestCommonPrefix
{
    public static void main(String[] args)
    {
        String[] strs={"aca","aba"};
        System.out.println(Solution.longestCommonPrefix(strs));
    }
}
class Solution
{
    public static String longestCommonPrefix(String[] strs)
    {
        if (strs==null)
            return null;
        int minLength=strs[0].length();
        int i,j;
        StringBuilder answer=new StringBuilder();
        for (i=0;i<strs.length;i++)
        {
            if (minLength > strs[i].length())
                minLength = strs[i].length();
        }
        for (i=0;i<minLength;i++)
        {
            char ch = strs[0].charAt(i);
            for (j = 0; j < strs.length; j++)
            {
                if (ch != strs[j].charAt(i))
                    break;
            }
            if (j >= strs.length)
                answer.append(ch);
            else
                break;
        }
        return answer.toString();
    }
}